package com.lbt.weixin.common.dao.impl;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.lbt.framework.dao.BasicDao;
import com.lbt.framework.general.Page;
import com.lbt.framework.general.Searching;
import com.lbt.weixin.common.bean.entity.Car;
import com.lbt.weixin.common.bean.entity.User;
import com.lbt.weixin.common.bean.search.Car4Search;
import com.lbt.weixin.common.dao.CarDao;


/**
 * Dao实现－车牌信息
 * @author Moyq5
 * @date 2016年9月24日
 */
@Repository("carDao")
public class CarDaoImpl extends BasicDao<Car> implements CarDao {

	public CarDaoImpl() {
		super(Car.class);
	}

	@Override
	protected Criteria getExample(Car entity, String searchWord) {
		Criteria c = super.getExample(entity, searchWord);
		
		// 用户信息
		User user = entity.getUser();
		if (null != user) {
			if (null != user.getUserId()) {
				c.add(Restrictions.eq("user.userId", user.getUserId()));
			} else {
				//...
			}
		}
		
		return c;
	}
	
	@Override
	public Page<Car> list(Car4Search car4s, Searching si) {
		Criteria c = getExample(car4s, si.getSearchWord());
		// TODO 在这里实现其它属性（条件）的查询
		return list(c, si);
	}
	
}
